<?php

namespace backend\utils;

use Yii;

class requestData
{
    const APPKEY = "185d55baa58446ee8aca2e6d74131619";
    const APPSECRET = "3ea1942f563a476f5b07c6b24f11366a";
    const URL = "https://basic.jxeduyun.com/sso-oauth";

    /*
     * 请求
     * */
    public static function sendCurl($route_url, $timeout=60, $params = [])
    {
        $url = self::URL . $route_url;

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);


        $post_data = http_build_query($params);

        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'accept: application/json, text/plain, */*',
            'accept-encoding:gzip, deflate',
            'accept-language: zh-CN,zh;q=0.9,en;q=0.8',
            'connection:keep-alive',
            //'Content-Type: application/json; charset=UTF-8',
            'Content_type: application/x-www-form-urlencoded',
            'Content-Length: ' . strlen($post_data),
            //"access-token:{$token}",
        ));
        curl_setopt($ch, CURLOPT_POST, 1);
        //参数为1表示传输数据，为0表示直接输出显示。
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        //参数为0表示不带头文件，为1表示带头文件
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_ENCODING, 'accept-encoding:gzip, deflate, br');// 'accept-encoding:gzip, deflate, br', 不然乱码
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

        $output = curl_exec($ch);
        curl_close($ch);

        return $output;
    }
}

